<?php
class LoginAction extends CommonAction {

	public function loginPre(){
		
		$this->display("login");
	}
	
    // 处理表单数据
    public function loginCheck() {
        $Dao = M("user");
        $account = $_POST['account'];
        $password = md5($_POST['password']);
       // echo $account;
        $list = $Dao->where("account = '$account' and password = '$password'")->find();
       // $list = $Dao->find();
        if(!empty($list)){
        
        	 $this->display("adminFrame:admin");
        }else{
        	header("Content-Type:text/html; charset=utf-8");
        	exit($Dao->getError().' [ <A HREF="javascript:history.back()">返 回</A> ]');
        }
    }
    
    
    //添加用户
    public function useradd(){
    	$Dao = M("user");
    	if($_POST['password'] != $_POST['repassword']){
    		$this->error('两次密码不一致！');
    	}
    	if($Dao->create()){
    		$Dao->password=md5($Dao->password);
    		if (false !== $Dao->add()) {
                $this->success('数据添加成功！');
            } else {
                $this->error('数据写入错误');
            }
        }else{
        	header("Content-Type:text/html; charset=utf-8");
        	exit($Dao->getError().' [ <A HREF="javascript:history.back()">返 回</A> ]');
        }
    }

    //修改密码
    public function update(){
    	$Dao = M('user');
    	if($Dao->create()){
    		$Dao->password = md5($Dao->password);
    		$Dao->save();
    		$this->success();
    	}
    }
}
?>
